import 'package:get/get.dart';
import 'package:get/route_manager.dart';

import '../../app/config.dart';
import 'intl_base.dart';

enum LanguageType { zh, en }

extension LanguageTypeKeys on LanguageType {
  String get language {
    switch (this) {
      case LanguageType.zh:
        return "zh";
      case LanguageType.en:
        return "en";
    }
  }
}

class TranslationsService extends Translations {

  @override
  Map<String, Map<String, String>> get keys {

    var keys = <String, Map<String, String>>{};

    final intlConfig = appGlobalConfig.intlConfig;

    for (var item in intlConfig.supportLanguages) {

      switch (item) {
        case LanguageType.zh:
          keys[item.language] = intlConfig.intlValues.fold({}, (e, b) {
            return e..addAll(IntlBase.zhIntl(b));
          });
          break;

        case LanguageType.en:
          keys[item.language] = intlConfig.intlValues.fold({}, (e, b) {
            return e..addAll(IntlBase.enIntl(b));
          });
          break;
      }
    }
 
    return keys;
  }
}
